package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;

import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色前端控制器
 */
@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户添加
     * @param
     */
    @PutMapping
    @ApiOperation(value = "用户添加", notes = "用户添加")
    public ResponseResult createUser(@RequestBody UserDto userDto) {
        userService.createUser(userDto);
        return ResponseResult.success();

    }

    /**
     * 用户修改
     */
    @PatchMapping
    @ApiOperation(value = "用户修改", notes = "用户修改")
    public ResponseResult modify(@RequestBody UserDto userDto) {
        userService.modify(userDto);
        return ResponseResult.success();
    }


    /**
     * 当前用户
     */
    @GetMapping("/current-user")
    @ApiOperation(value = "当前用户", notes = "当前用户")
    public ResponseResult currentUser() {


        return null;

    }

    /**
     * 启用禁用
     */
    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation(value = "启用禁用", notes = "启用禁用")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable String status) {

        userService.enableOrDisable(id, status);

        return ResponseResult.success();
    }

    /**
     * 用户列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "用户列表", notes = "用户列表")
    public ResponseResult<List<UserVo>> userList(@RequestBody UserDto userDto) {

        List<UserVo> userVos = userService.userList(userDto);
        return ResponseResult.success(userVos);
    }

    /**
     * 用户分页
     */
    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "用户分页", notes = "用户分页")
    public ResponseResult<PageResponse<UserVo>> findByPage(@RequestBody UserDto userDto,
                                                           @PathVariable int pageNum
            , @PathVariable int pageSize) {
        PageResponse<UserVo> pageInfo = userService.findByPage(userDto, pageNum, pageSize);
        return ResponseResult.success(pageInfo);

    }

    /**
     * 删除用户
     */
    @DeleteMapping("/remove/{userId}")
    @ApiOperation(value = "删除用户", notes = "删除用户")
    public ResponseResult deleteByUserId(@PathVariable String userId) {
        userService.deleteByUserId(userId);

        return ResponseResult.success();
    }


    /**
     * 密码重置
     */
    @PostMapping("/reset-passwords/{userId}")
    @ApiOperation(value = "密码重置", notes = "密码重置")
    public ResponseResult resetPassword(@PathVariable String userId) {

        userService.resetPassword(userId);
        return ResponseResult.success();
    }


}
